﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'usp_UPDMS_COM_FILE_Delete_By_File_Id')
	BEGIN
		DROP Procedure usp_UPDMS_COM_FILE_Delete_By_File_Id
	END
GO

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
/******************************************************************************
**	Name : usp_UPDMS_COM_FILE_Delete_By_File_Id
**	Desc : 특정 첨부파일을 삭제한다.
**	Test Exec Query : Exec usp_UPDMS_COM_FILE_Delete_By_File_Id ''
**	Called by : Com_Dac_UPDMS_COM_FILE.cs
**	Program ID : Anywhere
**	Auth : 송시명
**	Date : 2013-06-14
*******************************************************************************
**	Change History
*******************************************************************************
**	Date:		Author:		Description:
**	--------	--------	---------------------------------------
**	
*******************************************************************************/
CREATE PROC [dbo].[usp_UPDMS_COM_FILE_Delete_By_File_Id]
@ls_xml nvarchar(max) = '<UPDMS></UPDMS>' --루트노드
AS

BEGIN

DECLARE @iXmlHandle int
EXEC sp_xml_preparedocument @iXmlHandle OUTPUT, @ls_xml

DELETE FROM UPDMS_COM_FILE
 WHERE File_Id IN (
         SELECT File_Id
           FROM OPENXML(@iXmlHandle, '/UPDMS/UPDMS_COM_FILE', 2)
           WITH ( File_Id int ) x
       )

--메모리 해제
EXEC sp_xml_removedocument @iXmlHandle

END

GO

/*
--Test Exec Query--

DECLARE @ls_xml nvarchar(max) 
SET @ls_xml='<UPDMS><UPDMS_COM_FILE><File_Id>112</File_Id></UPDMS_COM_FILE><UPDMS_COM_FILE><File_Id>Ref1012m</File_Id></UPDMS_COM_FILE></UPDMS>'

EXEC usp_UPDMS_COM_FILE_Delete_By_File_Id @ls_xml

*/